import axios from "axios"
async function getRequest(url, query='') {
    let result
    let head = 'http://localhost:3000/'
    const p =  new Promise((resolve, reject) => {
        axios.get(head + url+query).then(response => {
            resolve(response)
        },
            error => {
            reject(error) 
        })
    })
    await p.then(response => {
        result = response
    }, error => {
        result =error
    })
    return result
}
async function getReq(url, query='') {
    let result
    let head = 'http://localhost:3000/'
    const p =  new Promise((resolve, reject) => {
        axios.get(head + url+query).then(response => {
            resolve(response)
        },
            error => {
            reject(error) 
        })
    })
    await p.then(response => {
        result = response
    }, error => {
        result =error
    })
    return result
}
async function postRequest(url, params = {}) {
    let result
    let head = 'http://localhost:3000/'
    const p = new Promise((resolve, reject) => {
        axios.post(head + url, params).then(response => {
            resolve(response)
        },
            error => {
            reject(error)
        })
    })
    await p.then(response => {
        result =response
    }, error => {
        result = error
    })
    return result
}
export {
    getRequest,
    getReq,
    postRequest
}